/**
 * Created by no1 on 2015/7/3.
 */

'use strict';
var mongoose = require('mongoose');
var C = require('../../../config');
//var fs = require('fs');
//var path = require('path');

module.exports = {
    models: require('./models'),
    CategoryDao: require('./CategoryDao'),
    DistrictDao: require('./DistrictDao'),
    ShopDao: require('./ShopDao'),
    VendorDao: require('./VendorDao'),
    WareDao: require('./WareDao'),
    WareVersionDao: require('./WareVersionDao'),
    AppConfigDao: require('./AppConfigDao'),
    SellPermissionDao: require('./SellPermissionDao'),
    SellRoleDao: require('./SellRoleDao'),
    SellUserDao: require('./SellUserDao'),
    CouponDao: require('./CouponDao'),
    ReceiveLogDao: require('./ReceiveLogDao')

};

try {
    mongoose.connect(C.mongo.uri, C.mongo.options);
} catch (err) {
    console.log(err);
}


var db = mongoose.connection;
db.on('error', function (err) {
    console.error('connect to %s error: ', C.mongo.uri, err.message);
    process.exit(1);
});
db.once('open', function () {
    console.log('%s has been connected.', C.mongo.uri);
});

//var models_path = __dirname + '/models';
//fs.readdirSync(models_path).forEach(function (file) {
//    var tmp = require(models_path + '/' + file);
//    var modelName = file.replace('.js', '');
//    exports[modelName] = tmp;
//});

//var dao_path = __dirname + '/../mongoDao';
//exports.Dao = {};
//fs.readdirSync(dao_path).forEach(function (file) {
//    if (file.match(/.*Dao\.js/)) {
//        var tmp = require(dao_path + '/' + file);
//        var modelName = file.replace('Dao.js', '');
//        exports.Dao[modelName] = tmp;
//    }
//});


//写入一条记录
//let db = require('./mongoModel');
//let ware = new db.ware({name: 'nihao'});
//let date = yield ware.save();
//if(date){
//  console.log(date);
//}
//查询一条记录
//let date =yield db.ware.find();
//if(date){
//  console.log(date[0]);
//}